package com.wx.handler.wx;

import com.wx.builder.TextBuilder;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

import static me.chanjar.weixin.common.api.WxConsts.XmlMsgType;

/**
 * @author Binary Wang(https://github.com/binarywang)
 */
@Component
public class MsgHandler extends AbstractHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService weixinService,
                                    WxSessionManager sessionManager) {

        StringBuilder stringBuilder = new StringBuilder();
        if(wxMessage.getMsgType().equals(XmlMsgType.TEXT)){
            if (StringUtils.startsWithAny(wxMessage.getContent(), "你好", "客服", "哈哈", "哈喽")){
                stringBuilder.append("您好，有什么事，很高兴为您服务");
            }else{
                stringBuilder.append("对不起，我还没那么智能，待我把内功修炼好再来回复您");
            }
        }else{
            stringBuilder.append("请稍等，我正在召唤主人，不要着急呀");
        }
        return new TextBuilder().build(stringBuilder.toString(), wxMessage, weixinService);

    }

}
